package com.lianxi.jdbc;

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Created by Administrator on 2018/4/26 0026.
 */
public class Dameng2DBHelper {
    private static BasicDataSource ds = new BasicDataSource();

    static {
        String driver = "dm.jdbc.driver.DmDriver";
        String url = "jdbc:dm://192.168.1.46:5237/?schema=XYZX";
        String user = "XYZX";
        String pwd = "hnzfmz371R";

        String initSize = "5";
        String maxSize = "60000";
        //创建连接池
        ds = new BasicDataSource();
        //设置参数
        ds.setDriverClassName(driver);
        ds.setUrl(url);
        ds.setUsername(user);
        ds.setPassword(pwd);
        ds.setInitialSize(new Integer(initSize));
        ds.setMaxActive(new Integer(maxSize));
    }

    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }

    public static void close(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw new RuntimeException("关闭连接失败", e);
            }
        }
    }


}
